fix(deno): Handle reader.closed rejection from releaseLock() in streaming#20187
fix(deno): Handle reader.closed rejection from releaseLock() in streaming#20187andreiborza merged 3 commits intodevelopfrom
reader.closed rejection from releaseLock() in streaming#20187Conversation
…treaming Replace `reader.closed.finally(() => onDone())` with `reader.closed.then(() => onDone(), () => onDone())` in `monitorStream`. Per the WHATWG Streams spec, `reader.releaseLock()` rejects `reader.closed` when the promise is still pending. `.finally()` propagates that rejection as an unhandled promise rejection, while `.then(f, f)` suppresses it by handling both the fulfilled and rejected cases. Closes: #20177
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Core
Deps
Other
Bug Fixes 🐛Deno
Other
Internal Changes 🔧Deps
Other
🤖 This preview updates automatically when you update the PR. |
size-limit report 📦
|
s1gr1d
left a comment
There was a problem hiding this comment.
Seems like a good approach - looks good 👍
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 7f65c39. Configure here.
| e.preventDefault(); | ||
| unhandledRejection = e; | ||
| }; | ||
| globalThis.addEventListener('unhandledrejection', handler); |
There was a problem hiding this comment.
Unhandled rejection listener registered after triggering action
Low Severity
The unhandledrejection event listener is registered on line 46, after reader.releaseLock() on line 39 which is the action that would trigger the rejection. If the fix were ever reverted to .finally(), the unhandled rejection event could fire before the listener is attached, causing the assertEquals(unhandledRejection, undefined, ...) assertion to pass incorrectly — hiding the regression the test is meant to catch. The listener needs to be set up before reader.releaseLock() to reliably detect unhandled rejections. Also, the test uses setTimeout(resolve, 50) which is a sleep-in-test pattern; a more deterministic signal would be preferable.
Triggered by project rule: PR Review Guidelines for Cursor Bot
Reviewed by Cursor Bugbot for commit 7f65c39. Configure here.


This PR replaces
reader.closed.finally(() => onDone())withreader.closed.then(() => onDone(), () => onDone())inmonitorStream.Per the WHATWG Streams spec,
reader.releaseLock()rejectsreader.closedwhen the promise is still pending..finally()propagates that rejection as an unhandled promise rejection, while.then(f, f)suppresses it by handling both the fulfilled and rejected cases.I was not able to reproduce the error directly on my deno version but this should prevent the issue.
Closes: #20177